import requests
import time
from tqdm import tqdm


def tqdm_study():
    text = ""
    for char in tqdm(["a", "b", "c", "d"]):
        text = text + char
        time.sleep(0.5)


def tqdm_download():
    url = "http://192.168.2.121/%E4%B8%80%E6%8B%B3%E4%BA%BA%20%E7%AC%AC%E4%BA%8C%E5%AD%A3%20%E7%AC%AC06%E9%9B%86%20%E6%80%AA%E4%BA%BA%E8%9C%82%E8%B5%B7%20720P%20AVC.mp4"
    headers = {"Range": "bytes={first_byte}={file_size}"}
    response = requests.get(url, stream=True, headers=headers)
    file_size = int(response.headers['content-length'])
    first_byte = 0

    pbar = tqdm(total=file_size, initial=first_byte, unit='B', unit_scale=True, desc="1.mp4")
    with open("1.mp4", 'ab') as f:
        for chunk in response.iter_content(chunk_size=1024):
            if chunk:
                f.write(chunk)
                pbar.update(1024)
    pbar.close()

if __name__ == '__main__':
    tqdm_download()